#ifndef SRC_LTTRY_H_
#define SRC_LTTRY_H_

#include "src/ltbase.h"
#include "src/lterr.h"
#include "src/ltlog.h"

lt_ForceInline void
lttry_ErrorLog(lterr_Code code, char const* file, lt_U32 line,
               char const* expr) {
    ltlog_Log5(Error, "try error", "expr", String(expr), "file", String(file),
               "line", U32(line), "error", U32(code), "errorName",
               String(lterr_Name(code)));
}

#define lttry_Try(M_expr)                                                      \
    do {                                                                       \
        lterr_Code lttry_code__ = (M_expr);                                    \
        if (lttry_code__ == lterr_kOk)                                         \
            break;                                                             \
        lttry_ErrorLog(lttry_code__, __FILE__, __LINE__, #M_expr);             \
        return lttry_code__;                                                   \
    } while (0)

#endif // SRC_LTTRY_H_
